//
//  XDMiyoshiBankCountViewController.m
//  XDEducation
//
//  Created by 星道 on 17/5/13.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDMiyoshiBankCountViewController.h"
#import "XDMiyoshiBankCountModel.h"

#import "XDMiyoshiBankErrProblemViewController.h"

@interface XDMiyoshiBankCountViewController ()
{
    IBOutlet UILabel *_Count;       //总收入
    IBOutlet UILabel *_Worth;       //价值
    IBOutlet UILabel *_Rank;        //排名
    IBOutlet UILabel *_ThankFlower; //感恩的心
    IBOutlet UILabel *_Flower;      //红花数
    IBOutlet UILabel *_GoodStudy;   //好成绩
    IBOutlet UILabel *_GoodHobby;   //好习惯
    IBOutlet UILabel *_GoodAttainment;  //好素养
    IBOutlet UILabel *_Evaluation;  //三好动态评价
}
@end

@implementation XDMiyoshiBankCountViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self NetData];
}


/** 网络请求 */
- (void)NetData
{
    [MBProgressHUD showHUD];
    [XDHttpTool get:BaseURL(@"user.do?action=getMyFruitSummary") authCode:[AccountTool shareAccountTool].currentAccount.authCode params:nil success:^(id responseObj) {
        
        if ([responseObj[@"code"] isEqualToNumber:@1000])
        {
            XDMiyoshiBankCountModel *Model = [[XDMiyoshiBankCountModel alloc] initWithDict:responseObj[@"t"]];
            [self RefreshUI:Model];
        }
        else
        {
            [MBProgressHUD showError:XDNetWorkError];
        }
        
    } failure:^(NSError *error) {
        [MBProgressHUD showError:XDNetWorkError];
    }];
}




#pragma mark - 界面刷新
/** 更新界面 */
- (void)RefreshUI:(XDMiyoshiBankCountModel *)Model
{
    //规则
    //红花数=好成绩+好习惯+好素养+三好动态评价
    //中间的红花数=感恩的心
    //总收入= 红花数+感恩的心/中间的红花数
    //下
    _GoodStudy.text = [Model.goodStudy stringValue];
    _GoodHobby.text = [Model.goodHobby stringValue]?:@"0";
    _GoodAttainment.text = [Model.goodAttainment stringValue];
    _Evaluation.text = [Model.evaluation stringValue];
    _Flower.text = [
                    NSString stringWithFormat:@"%ld",
                    [Model.goodHobby integerValue] +
                    [Model.goodStudy integerValue] +
                    [Model.goodAttainment integerValue] +
                    [Model.evaluation integerValue]
                    ];
    //中
    _ThankFlower.text = [Model.thanksGiving stringValue];
    //上
    _Rank.text = [Model.rank stringValue];
    _Count.text = [@([_Flower.text integerValue] + [_ThankFlower.text integerValue]) stringValue];
    _Worth.text = [@([_Count.text integerValue] / 500.0) stringValue];
}




#pragma mark - Action
/** 错题集中营 */
- (IBAction)ErrorProblem:(UIButton *)sender
{
    XDMiyoshiBankErrProblemViewController *ErrProblem = [[XDMiyoshiBankErrProblemViewController alloc] init];
    ErrProblem.title = @"错题集中营";
    [self.navigationController pushViewController:ErrProblem animated:YES];
    
}

@end
